import java.util.Scanner;

//unique and occurrences of duplicate numbers
//													The input array is 1 5 2 7 3 2 8 4 
//													
//													Occurrence count of duplicate numbers 
//													2 is duplicated 2 times in the array 
//													
//													Unique numbers in the array are 1, 5, 7, 3, 8, 4, 
//													
//												************************************************************
//
//													The input array is 3 3 6 2 9 3 6 2 1 9 3 1 4 7 1 
//													
//													Occurrence count of duplicate numbers 
//													6 is duplicated 2 times in the array 
//													2 is duplicated 2 times in the array 
//													9 is duplicated 2 times in the array 
//													3 is duplicated 4 times in the array 
//													1 is duplicated 3 times in the array 
//													
//													Unique numbers in the array are 4, 7, 
//

public class Assignment4 {
	public static void main(String args[]) {
		CalcAPI myapi = new CalcAPI();		
		System.out.println("Enter the number of inputs");
		Scanner s = new Scanner(System.in);
		int numOfInputs = s.nextInt();
		int[] myArray = new int[numOfInputs];
		int[] uniquearray = new int[numOfInputs];
		int uniqueindex = 0;
		for(int i=0;i<numOfInputs;i++) {
			System.out.println("Enter integer input #" + (i+1));
			myArray[i] = myapi.getIntInput();				
		}
		System.out.format("%nThe input array is ");
		for(int i=0;i<numOfInputs;i++) {
			System.out.print(myArray[i] + " ");			
		}
		System.out.format("%n%nOccurrence count of duplicate numbers %n");
		for(int i=0;i<numOfInputs;i++) {
			int currentnum = myArray[i];
			int occurrencecount = 0;
			boolean isunique = true;
			for(int j=0;j<numOfInputs;j++) {
				if((currentnum == myArray[j])&&(i!=j)) {
					isunique = false;
					if(i<j) //duplicate number occurrence already printed
						occurrencecount = 0;
					else 
						occurrencecount++;
				}
				
			}
			if(isunique) {
				uniquearray[uniqueindex] = myArray[i];
				uniqueindex++;
			}
			if((!isunique)&&(occurrencecount != 0))
				System.out.format("%d is duplicated %d times in the array %n" , myArray[i], occurrencecount+1);
		}
		System.out.println();
		System.out.print("Unique numbers in the array are ");
		for(int i=0;i<uniqueindex;i++) {
			System.out.print(uniquearray[i] + ", ");			
		}
		System.out.println();
		
		
	}
}
